/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 *
 */

import { isWindows } from '@ohos/hvigor';
import { Component } from '@ohos/sdkmanager-common';
import path from 'path';

import { SdkComponent } from '../superior/sdk-component.js';

/**
 * ohos sdk native实例类
 *
 * @since 2021/1/21
 */
export class SdkNativeComponent extends SdkComponent {
  private readonly _ninjaTool: string;
  private readonly _cmakeTool: string;
  private readonly _nativeToolchain: string;
  private readonly _llvmStrip: string;
  private readonly _llvmReadElf: string;

  constructor(component: Component) {
    super(component);
    const cmakeApp = isWindows() ? 'cmake.exe' : 'cmake';
    const ninjaApp = isWindows() ? 'ninja.exe' : 'ninja';
    const llvmStripApp = isWindows() ? 'llvm-strip.exe' : 'llvm-strip';
    const llvmReadElfApp = isWindows() ? 'llvm-readelf.exe' : 'llvm-readelf';
    this._ninjaTool = path.resolve(this.getBaseDir(), 'build-tools', 'cmake', 'bin', ninjaApp);
    this._cmakeTool = path.resolve(this.getBaseDir(), 'build-tools', 'cmake', 'bin', cmakeApp);
    this._nativeToolchain = path.resolve(this.getBaseDir(), 'build', 'cmake', 'ohos.toolchain.cmake');
    this._llvmStrip = path.resolve(this.getBaseDir(), 'llvm', 'bin', llvmStripApp);
    this._llvmReadElf = path.resolve(this.getBaseDir(), 'llvm', 'bin', llvmReadElfApp);
  }

  getCmakeTool(): string {
    return this._cmakeTool;
  }

  getNinjaTool(): string {
    return this._ninjaTool;
  }

  getNativeToolchain(): string {
    return this._nativeToolchain;
  }

  getLlvmStrip(): string {
    return this._llvmStrip;
  }

  getLlvmReadElf(): string {
    return this._llvmReadElf;
  }
}
